/*
 * File: exercise17.cpp
 * -------------------
 * encodeCaesarCipher function 
 * compile command :
 * g++ -Wall -g exercise17.cpp -o exercise17 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include "simpio.h"
#include <string>
using namespace std;

string encodeCaesarCipher(string str, int shift);

int main()
{
	cout<<"This program encodes a message using a Caesar cipher."<<endl;
	int shift = getInteger("Enter the number of character positions to shift: ");
	string str = getLine("Enter a message: ");
	cout<<"Encoded message: "<<encodeCaesarCipher(str, shift)<<endl;
	return 0;
}

string encodeCaesarCipher(string str, int shift)
{
	int nchars = str.length();
	string result = "";
	for(int i = 0; i < nchars; i++)
	{
		if(isupper(str[i]))
		{
			result += 'A' + (str[i]-'A'+shift+26) %26;
		}
		else if(islower(str[i]))
		{
			result += 'a' + (str[i]-'a'+shift+26) %26;
		}
		else
			result += str[i];
	}
	return result;
}
